<?php
/**
 * 短信验证码服务
 * zhouliang
 * 2020.08.29
 */

namespace App\Services\Tools;
use App\Exceptions\BasicException;

class SmsService {

    public static $_instance ;

    public static function getInstance(){
//        if(!isset(self::$_instance)){
//            $sms_handel = app('model_config')->getValue('SMS_HANDEL');
//            if($sms_handel == 'yunji'){
//                self::$_instance =  new SmsYunjiService();
//            }else{
//                self::$_instance =  new EasySmsService();
//            }
//        }
        if(!isset(self::$_instance)){
            self::$_instance =  new NeteaseSmsService();
        }
        return self::$_instance;
    }


    /**
     * @param $mobile int 手机号码
     * @param $type int 类型 1注册 2找回密码 3验证旧手机 4.绑定新手机 5.设置二级密码 6.绑定银行卡 7.找回qq账号 8.注销账号 9.快捷认证(支付宝身份验证) 10.人工认证
     * @param array $param 参数
     * @param int $limit 单位:分钟
     * @return string
     */
    public static function send($mobile, $type, $param = [], $limit = 1,$template_id='') {
        return self::getInstance()::send($mobile, $type, $param , $limit,$template_id);
    }

    //给风控管理员发预警短信
    public static function sentryToAdmin($code)
    {
        return self::getInstance()::sentryToAdmin($code);
    }

    public static function sentryThreeToUser($msg,$phone,$type=14)
    {

        if (env('SMS_REAL_SEND')){
            try{
                self::getInstance()::sendThreeWarningMsg($msg, $phone, $type);
                return  true;
            }catch (\Exception $er){
                return false;
            }

        }
        return true;
    }

    //用户账务异常风控报警
    static function sentryToAdminByAccount($code)
    {
        return self::getInstance()::sentryToAdminByAccount($code);
    }

    static function verify($mobile, $code, $type,$isCheckDev=0) {
        if (!env('SMS_REAL_SEND') && !$isCheckDev) {
            return true;
        }
        return self::getInstance()::verify($mobile, $code, $type);
    }

    public static function getErrorMsg(){
        return  self::getInstance()::getErrorMsg();
    }
}
